/**
 * author:Administrator
 * date:2013-5-21
 */
package com.roc.web.action;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

/**
 * @author Administrator
 *
 */
public class MerchantSearchCondition extends BaseSearchCondition {
	
	private boolean isAdmin=true;
	private Long superiorId;
	private String accountNo;
	private String mobile;
	private String realName;
	private String cardNo;
	private String minDate;
	private String maxDate;
	private String merType;
	private Object[] merchantNos;
	

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getOrderPartOfHQL()
	 */
	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		
		return " order by t.accountNo,t.dtCreate ";
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getRowCountHQL()
	 */
	@Override
	protected String getRowCountHQL() {
		// TODO Auto-generated method stub
		if(isAdmin==false){
			return " select count(*)  from Merchant t where 1=1 and (t.id="+superiorId+" or t.superiorId="+superiorId+")";
			
		}
		return " select count(*) from Merchant t where 1=1 ";
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getSearchHQL()
	 */
	@Override
	protected String getSearchHQL() {
		// TODO Auto-generated method stub
		if(isAdmin==false){
			return " from Merchant t where 1=1 and (t.id="+superiorId+" or t.superiorId="+superiorId+")";
			
		}
		return " from Merchant t where 1=1  ";
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getWhereHQLFieldBeanList()
	 */
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();

		
		if (Constance.isNotEmpty(accountNo)) {
			filedBeanList.add(new WhereHQLFieldBean("t.accountNo", accountNo.trim()
					.trim(), "=", false));
		}

		if (Constance.isNotEmpty(realName)) {
			filedBeanList.add(new WhereHQLFieldBean("t.realName", realName.trim(),
					"LIKE", false, "ALL"));
		}
		if (Constance.isNotEmpty(mobile)) {
			filedBeanList.add(new WhereHQLFieldBean("t.mobile", mobile.trim()
					.trim(), "=", false));
		}
		if (Constance.isNotEmpty(cardNo)) {
			filedBeanList.add(new WhereHQLFieldBean("t.cardNo", cardNo.trim()
					.trim(), "=", false));
		}
		if (Constance.isNotEmpty(merType)&&!"99".equals(merType)) {
			filedBeanList.add(new WhereHQLFieldBean("t.merType", merType.trim()
					.trim(), "=", false));
		}
        
        if(Constance.isNotEmpty(minDate)&&Constance.isNotEmpty(maxDate)){
        	Date startDate=Constance.formateDate(minDate);
        	Date endDate =Constance.formateDate(maxDate);
        	filedBeanList.add(new WhereHQLFieldBean("t.dtCreate",startDate,
					">=", false));
        	filedBeanList.add(new WhereHQLFieldBean("t.dtCreate",endDate,
					"<=", false));
        }
        if(merchantNos!=null&&merchantNos.length>0){
        	filedBeanList.add(new WhereHQLFieldBean("t.accountNo",merchantNos,
					"IN", false));
        }

		return filedBeanList;
	}

	/**
	 * @return the accountNo
	 */
	public String getAccountNo() {
		return accountNo;
	}

	/**
	 * @param accountNo the accountNo to set
	 */
	public void setAccountNo(String accountNo) {
		this.accountNo = accountNo;
	}

	/**
	 * @return the mobile
	 */
	public String getMobile() {
		return mobile;
	}

	/**
	 * @param mobile the mobile to set
	 */
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	/**
	 * @return the realName
	 */
	public String getRealName() {
		return realName;
	}

	/**
	 * @param realName the realName to set
	 */
	public void setRealName(String realName) {
		this.realName = realName;
	}

	/**
	 * @return the cardNo
	 */
	public String getCardNo() {
		return cardNo;
	}

	/**
	 * @param cardNo the cardNo to set
	 */
	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	/**
	 * @return the minDate
	 */
	public String getMinDate() {
		return minDate;
	}

	/**
	 * @param minDate the minDate to set
	 */
	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}

	/**
	 * @return the maxDate
	 */
	public String getMaxDate() {
		return maxDate;
	}

	/**
	 * @param maxDate the maxDate to set
	 */
	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}

	/**
	 * @return the isAdmin
	 */
	public boolean isAdmin() {
		return isAdmin;
	}

	/**
	 * @param isAdmin the isAdmin to set
	 */
	public void setAdmin(boolean isAdmin) {
		this.isAdmin = isAdmin;
	}

	/**
	 * @return the superiorId
	 */
	public Long getSuperiorId() {
		return superiorId;
	}

	/**
	 * @param superiorId the superiorId to set
	 */
	public void setSuperiorId(Long superiorId) {
		this.superiorId = superiorId;
	}

	/**
	 * @return the merType
	 */
	public String getMerType() {
		return merType;
	}

	/**
	 * @param merType the merType to set
	 */
	public void setMerType(String merType) {
		this.merType = merType;
	}




	

	/**
	 * @return the merchantNos
	 */
	public Object[] getMerchantNos() {
		return merchantNos;
	}

	/**
	 * @param merchantNos the merchantNos to set
	 */
	public void setMerchantNos(Object[] merchantNos) {
		this.merchantNos = merchantNos;
	}

	public static void main(String[] args) {
		MerchantSearchCondition s=new MerchantSearchCondition();
		Object[] ids=new Object[]{"dxpeng","lisi","wangwu"};
		s.setSuperiorId(1l);
		s.setMerchantNos(ids);
		try {
			System.out.println(s.getMerchantNos().length);
			System.out.println(s.getFullSearchHQL(null));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
